#ifndef GLOBAL_DATA_H
#define GLOBAL_DATA_H

#define GRID_HEIGHT		15
#define GRID_WIDTH		15

#include "../WindowClass/OpenGlClass.h"
#include "../Input/InputControl.h"
#include "../Graphics.h"
#include "../Math/MathCode.h"
#include "../SmartObjects/SmartObjects.h"
#include "../InputProcs.h"
#include "../Timer/timer.h"
#include <vector>
#include <list>



class WorldMap;

extern OpenGLWindow gWindow;
extern Input gInput;
extern GraphicsSystem gGraphics;
extern WorldMap gWorldMap;

extern float gMouseX;
extern float gMouseY;

extern bool gPause;
extern bool gTabDown;
extern int gCurrentFile;

extern bool gChangeAttribute;
extern std::string gAttributeName;

class ObjectModel {
  public:
    ObjectModel( std::string textureName, Vector2f pos, Vector2f scale );
    ~ObjectModel();

    void MoveObject( Vector2f target );
    Vector2f GetPosition();
	Vector2f GetStevescale();

    SmartObject brain;
  private:
    Vector2f Stevescale;
    Vector2f position;
    unsigned int graphicID;
};

class AgentModel {
  public:
    AgentModel( std::string textureName, Vector2f pos, Vector2f scale, float speed );
    ~AgentModel();

    void MoveObject( Vector2f target );
    Vector2f GetPosition();

    bool UpdateMovement();
    void AttachPath( const std::vector<Vector2f>& newPath );
    void RemovePath();

    Timer timer;
    SmartAgent brain;
    bool pathingToObject;
  private:
    float speed;
    Vector2f position;
    unsigned int graphicID;
    std::vector<Vector2f> path;
};


struct WorldNode
{
	AgentModel *Agent;
	ObjectModel *Object;

	bool IsWall;

	struct
	{
		float x;
		float y;
	} Coords;
};

class WorldMap
{
public:
  typedef std::list<ObjectModel *> ObjList;
  typedef ObjList::iterator ObjIter;
  typedef std::list<AgentModel *> AgtList;
  typedef AgtList::iterator AgtIter;

	WorldMap();
	~WorldMap();

	bool RegisterObject(ObjectModel &Object, bool IsWall = false);
	void RegisterAgent(AgentModel &Agent);

	ObjList *GetObjects(void) {return &ObjectList;}
	AgtList *GetAgents(void) {return &AgentList;}

  bool IsWall( int posX, int posY );

	WorldNode WorldGrid[GRID_HEIGHT][GRID_WIDTH];

  void ClearMap();
  void ClearObjects();
  void ClearAgents();
private:

	ObjList ObjectList;
	AgtList AgentList;

	int InterpretCoord(float Offset) {return (int)Offset;}
};

extern AgentModel* gTargetAgent;
extern bool gTrackingOn;

#endif
